---GOAP代理，一个AI目标一个代理
---需要实现实现一整套状态流程规划及动作Action和目标Goal
---需要实现自定义自身Map来存储和初始化所有数据
---需要实现自定义ActionManager来对该AI进行动作添加
---需要实现自定义GoalManager来对该AI进行目标添加
---需要实现自定义TriggerManager来对该AI的触发监听添加
---@class AgentBase
---@field isAgentOver boolean 是否已经结束代理
---@field agentState State 代理的状态数据
---@field dataMap DataMapBase   数据中心
---@field actionManager ActionManagerBase 动作管理器
---@field goalManager GoalManagerBase   目标管理器
---@field performer Performer  执行者
---@field triggerManager TriggerManagerBase 触发器管理器
---@field base AgentBase
AgentBase = class()

function AgentBase:ctor()
    self.base = AgentBase;
    self.isAgentOver = false;
    self.agentState = self:InitAgentState();
    self.dataMap = self:InitDataMaps();
    self.actionManager = self:InitActionManager();
    self.goalManager = self:InitGoalManager();
    self.triggerManager = self:InitTriggerManager();
    self.performer = Performer.new(self);
    self.agentState:SetStateChangeCallFunc(function ()
        self:UpdateData();
    end)
    self:JudgeException(self.agentState,"agentState");
    self:JudgeException(self.dataMap,"map");
    self:JudgeException(self.actionManager,"actionManager");
    self:JudgeException(self.goalManager,"goalManager");
    self:JudgeException(self.triggerManager,"triggerManager");
end

function AgentBase:JudgeException(obj, name)
    if obj == nil then
        Debug.LogError("GOAP代理中"..name.."对象为空，请在代理子类中初始化该对象")
    end
end

---初始化代理的状态数据，子类重写
---@return State
function AgentBase:InitAgentState()
    local state = State.new();
    return state;
end

---初始化数据中心，子类重写
function AgentBase:InitDataMaps()
    local map = DataMapBase.new(self)
    return map;
end

---初始化动作管理器，子类重写
function AgentBase:InitActionManager()
    local actionMgr = ActionManagerBase.new(self);
    return actionMgr;
end

---初始化目标管理器，子类重写
function AgentBase:InitGoalManager()
    local goalMgr = GoalManagerBase.new(self);
    return goalMgr;
end
---初始化触发器管理器，子类重写
function AgentBase:InitTriggerManager()
    local triggerManager = TriggerManagerBase.new(self);
    return triggerManager;
end

---状态更新执行函数
function AgentBase:UpdateData()
    if self.isAgentOver then
        return;
    end
    if self.actionManager ~= nil then
        self.actionManager:UpdateData();
    end
    if self.goalManager ~= nil then
        self.goalManager:UpdateData();
    end

    self.performer:UpdateData();
end

---帧函数
function AgentBase:FrameFun()
    if self.isAgentOver then
        return;
    end
    if self.triggerManager ~= nil then
        self.triggerManager:FramFun();
    end
    if self.actionManager ~= nil then
        self.actionManager:FrameFun();
    end
end

---释放
function AgentBase:Release()

end